<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>帖子管理页面</title>
<link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/default/easyui.css"></link>
<link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/icon.css"></link>
<script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/static/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>

<script type="text/javascript">

	var url;
	
	function deleteFilm(){
		var selectedRows=$("#dg").datagrid("getSelections");
		if(selectedRows.length==0){
			 $.messager.alert("系统提示","请选择要删除的数据！");
			 return;
		 }
		 var strIds=[];
		 for(var i=0;i<selectedRows.length;i++){
			 strIds.push(selectedRows[i].id);
		 }
		 var ids=strIds.join(",");
		 $.messager.confirm("系统提示","您确定要删除这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r){
				if(r){
					$.post("/admin/film/delete",{ids:ids},function(result){
						if(result.success){
							 $.messager.alert("系统提示","数据已成功删除！");
						}else{
							$.messager.alert("系统提示",result.errorInfo);
						}
					   $("#dg").datagrid("reload");
					},"json");
				} 
	   });
	}
	
	function openFilmAddDialog(){
		$("#dlg").dialog("open").dialog("setTitle","添加帖子信息");
		url="/admin/film/save";
	}
	
	function openFilmModifyDialog(){
		var selectedRows=$("#dg").datagrid("getSelections");
		 if(selectedRows.length!=1){
			 $.messager.alert("系统提示","请选择一条要编辑的数据！");
			 return;
		 }
		 var row=selectedRows[0];
		 $("#dlg").dialog("open").dialog("setTitle","编辑帖子信息");
		 $("#fm").form("load",row);
		 url="/admin/film/save?id="+row.id;
	 }
	
	function saveFilm(){
		 $("#fm").form("submit",{
			url:url,
			onSubmit:function(){
				return $(this).form("validate");
			},
			success:function(result){
				var result=eval('('+result+')');
				if(result.success){
					$.messager.alert("系统提示","保存成功！");
					resetValue();
					$("#dlg").dialog("close");
					$("#dg").datagrid("reload");
				}else{
					$.messager.alert("系统提示","保存失败！");

				}
			}
		 });
	 }
	 
	function resetValue(){
		 $("#name").val("");
		 $("#url").val("");
		 $("#sort").val("");
	 }
	
	 function closeFilmDialog(){
		 $("#dlg").dialog("close");
		 resetValue();
	 }
	 
	 function formatImageName(val,row){
		 return "<img width=100 height=100 src='/static/filmImage/"+val+"'>";
	 }
	 
	 function formatHot(val,row){
		 if(val==1){
			 return "是";
		 }else{
			 return "不是";
		 }
	 }
	 
	 
	 function openFilmModifyTab(){
		 var selectedRows=$("#dg").datagrid("getSelections");
		 if(selectedRows.length!=1){
			 $.messager.alert("系统提示","请选择一个要修改的帖子！");
			 return;
		 }
		 var row=selectedRows[0];
		 window.parent.openTab('修改帖子','modifyFilm.html?id='+row.id,'icon-modifyFilm');
	}
	 
	function searchFilm(){
		$("#dg").datagrid('load',{
			"name":$("#s_name").val() 
		});
	}

</script>
</head>
<body style="margin: 1px">
<table id="dg" title="帖子管理" class="easyui-datagrid"
   fitColumns="true" pagination="true" rownumbers="true"
   url="/admin/film/list" fit="true" toolbar="#tb">
   <thead>
   	<tr>
   		<th field="cb" checkbox="true" align="center"></th>
   		<th field="id" width="20" align="center">编号</th>
   		<th field="imageName" width="50" align="center" formatter="formatImageName">帖子图片</th>
   		<th field="name" width="100" align="center">帖子名称</th>
   		<th field="title" width="200" align="center">帖子标题</th>
   		<th field="hot" width="50" align="center" formatter="formatHot">热门？</th>
   		<th field="publishDate" width="150" align="center">发布日期</th>
   	</tr>
   </thead>
 </table>
 <div id="tb">
 	<div>
 		<a href="javascript:openFilmModifyTab()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
 		<a href="javascript:deleteFilm()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
 	</div> 
 	<div>
 		&nbsp;帖子名称：&nbsp;<input type="text" id="s_name" size="20" onkeydown="if(event.keyCode==13) searchFilm()"/>
 		<a href="javascript:searchFilm()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
 	</div>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
 </div>
 
</body>
</html>